home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / Matlab mode / matlabMacros.tcl < prev    next >
Encoding:
Text File  |  1998-04-05  |  5.6 KB  |  194 lines

  1. ################################################################################
  2. #
  3. # matlabMacros.tcl, part of the matlab mode package
  4. # Send various commands to MATLAB
  5. ################################################################################
  6.  
  7. proc matlabMacros.tcl {} {}
  8.  
  9. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
  10. #
  11. # ◊◊◊◊ MATLAB Workspace ◊◊◊◊ #
  12. #
  13. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-
  14.  
  15. ################################################################################
  16. #  Reset MATLAB path
  17. ################################################################################
  18.  
  19. proc matlabRebuildPath {} {
  20.     set scriptName "path(path)"
  21.     matlabDoScript $scriptName 0
  22.     message $scriptName
  23. }
  24.  
  25.  
  26. ################################################################################
  27. #  Clears the current window's script/function from the workspace
  28. ################################################################################
  29.  
  30. proc matlabClearProcedure {} {
  31.     set mFile [lindex [winNames -f] 0]
  32.     set procName [file rootname [file tail $mFile]]
  33.     set scriptName "clear $procName"
  34.     matlabDoScript $scriptName 0
  35.     message $scriptName
  36. }
  37.     
  38.  
  39. ################################################################################
  40. #  Clears the workspace
  41. ################################################################################
  42.  
  43. proc matlabClear {} {
  44.     set scriptName "clear"
  45.     matlabDoScript $scriptName 0
  46.     message $scriptName
  47. }
  48.  
  49. ################################################################################
  50. #  Closes all figure windows
  51. ################################################################################
  52.  
  53. proc matlabCloseAll {} {
  54.     set scriptName "close all"
  55.     matlabDoScript $scriptName 0
  56.     message $scriptName
  57. }
  58.  
  59. ################################################################################
  60. # Get the path of the current window and add it to MATLAB's path
  61. ################################################################################
  62.  
  63. proc matlabAddToPath {} {
  64.  
  65.     set mFile [lindex [winNames -f] 0]
  66.     regsub -all {'} [file dirname $mFile] {''} mFilePath
  67.     matlabDoScript "path(path,'$mFilePath');" 0
  68.     message "Added '$mFilePath' to path."
  69.     
  70. }
  71.  
  72. ################################################################################
  73. # CD to the path of the current window
  74. ################################################################################
  75.  
  76. proc matlabCdToWin {} {
  77.  
  78.     set mFile [lindex [winNames -f] 0]
  79.     regsub -all {'} [file dirname $mFile] {''} mFilePath
  80.     matlabDoScript "cd('$mFilePath');" 0
  81.     message "cd('$mFilePath')"
  82.     
  83. }
  84.  
  85.  
  86. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
  87. #
  88. # ◊◊◊◊ MATLAB debugging ◊◊◊◊ #
  89. #
  90. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-
  91.  
  92. ################################################################################
  93. #  Turn on debugging
  94. ################################################################################
  95.  
  96. proc matlabStopIfError {} {
  97.     set scriptName "dbstop if error"
  98.     matlabDoScript $scriptName 0
  99.     message $scriptName
  100. }
  101.  
  102.  
  103. ################################################################################
  104. #  Turn off debugging
  105. ################################################################################
  106.  
  107. proc matlabDbClear {} {
  108.     set scriptName "dbclear all"
  109.     matlabDoScript $scriptName 0
  110.     message $scriptName
  111. }
  112.  
  113.  
  114. ################################################################################
  115. #  Turn on debugging for current window's script/function
  116. ################################################################################
  117.  
  118. proc matlabStopInFile {} {
  119.     set mFile [lindex [winNames -f] 0]
  120.     set procName [file rootname [file tail $mFile]]
  121.     set scriptName "dbstop in $procName"
  122.     matlabDoScript $scriptName 0
  123.     message $scriptName
  124. }
  125.  
  126.  
  127. ################################################################################
  128. #  Turn on debugging for current window's script/function
  129. ################################################################################
  130.  
  131. proc matlabStopAtCurrentLine {} {
  132.     set mFile [lindex [winNames -f] 0]
  133.     set procName [file rootname [file tail $mFile]]
  134.  
  135.     set lineno [lindex [posToRowCol [getPos]] 0]
  136.     
  137.     set scriptName "dbstop at $lineno in $procName"
  138.     matlabDoScript $scriptName 0
  139.     message $scriptName
  140. }
  141.  
  142.  
  143. ################################################################################
  144. #  Debug step
  145. ################################################################################
  146.  
  147. proc matlabDebugStep {{nlines 1}} {
  148.     set scriptName "dbstep $nlines"
  149.     matlabDoScript $scriptName
  150.     message $scriptName
  151. }
  152.  
  153.  
  154. ################################################################################
  155. #  List breakpoints for a file
  156. ################################################################################
  157.  
  158. proc matlabDebugStatus {} {
  159.     set mFile [lindex [winNames -f] 0]
  160.     set procName [file rootname [file tail $mFile]]
  161.     set scriptName "dbstatus $procName"
  162.     set res [matlabDoScript $scriptName 0]
  163.     set text "Breakpoints in $procName"
  164.     matlabShowDefinition $text $res
  165. }
  166.  
  167.  
  168. ################################################################################
  169. #  Open the file that caused the MATLAB error
  170. ################################################################################
  171.  
  172. proc matlabOpenErrorFile {} {
  173.     global lastMatlabResult
  174.     
  175.     if {[regexp -- {(Error in ==> )([^\r]*)([\r]On line )+([^=]*)(==>)} $lastMatlabResult d1 d2 mFile d3 line]} {
  176.         set fname [string trim $mFile]
  177.         set line [string trim $line]
  178.     
  179.         if {[catch {edit $mFile}]} {
  180.             beep
  181.             alertnote "Could not open file, $mFile"
  182.         } else {
  183.             set pos [rowColToPos $line 0]
  184.             select $pos [nextLineStart $pos]
  185.         }
  186.     } else {
  187.             beep
  188.             alertnote "No error or no file to open from last command."
  189.     }
  190. }
  191.  
  192.